package cn.edu.zafu.bigdata.x.Foo;

import java.io.*;
import java.net.*;

public class Client {
    public static void main(String[] args) throws IOException {
        String host = "192.168.16.38"; // 服务端IP地址
        int port = 3000; // 服务端端口
        Socket socket = new Socket(host, port);

        // 创建输入输出流
        BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));

        String userInput;
        System.out.println("Type messages to send to the server. Enter 'exit' to quit.");

        while ((userInput = stdIn.readLine()) != null) {
            if ("exit".equalsIgnoreCase(userInput)) {
                break;
            }
            out.println(userInput); // 发送消息到服务端
            System.out.println("Server response: " + in.readLine());
        }

        stdIn.close();
        in.close();
        out.close();
        socket.close();
    }
}
